﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TpBaseObjects.Objects;
using TpData.Layer;

namespace TpData.Manager {

    public class CommonDataManager {

        #region Members

        private static List<OrganisationsShortListObj> organisations;

        #endregion

        #region Load

        public static List<JobObj> LoadJobs(int ProjectID) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.Jobs(ProjectID);
            }
        }

        public static List<JobObj> LoadJobs(int CashSaleID, bool all) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.Jobs(CashSaleID, false);
            }
        }

        public static List<JobObj> LoadJobs(int UserID, byte all) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.Jobs(UserID, 0);
            }
        }

        public static List<JobObj> LoadJobs(Guid JobID) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.Jobs(JobID);
            }
        }

        public static List<JobObj> LoadJobs(short Status) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.Jobs(Status);
            }
        }

        public static List<string> LoadMitarbeiter() {
            using(CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.LoadMitarbeiter();
            }
        }

        public static List<OrganisationsShortListObj> LoadOrganisationsShortList() {
            return LoadOrganisationsShortList(false);
        }
        
        public static List<OrganisationsShortListObj> LoadOrganisationsShortList(bool reload) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                if (organisations == null || reload) {
                    organisations = dl.LoadOrganisationsShortList();
                }
                return organisations;
            }
        }

        public static List<PlzOrt> LoadPlzOrtList() {
            return LoadPlzOrtList(false);
        }

        public static List<PlzOrt> LoadPlzOrtList(bool withNull) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.LoadPlzOrtList(withNull);
            }
        }

        public static PlzOrt LoadPlzOrt(int EPLZ) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                return dl.LoadPlzOrt(EPLZ);
            }
        }

        public static List<CustomerGroupObj> LoadCustomerGroupList() {
            List<CustomerGroupObj> ret = new List<CustomerGroupObj>();
            for (int i = 0; i < 6; i++) {
                CustomerGroupObj cg = new CustomerGroupObj();
                cg.CustomerGroupID = Convert.ToByte(i);
                if (i > 0) {
                    cg.CustomerGroupText = i.ToString();
                } else {
                    cg.CustomerGroupText = "";
                }
                ret.Add(cg);
            }
            return ret;
        }

        #endregion

        #region Save

        public static void SaveJob(JobObj job) {
            using (CommonDataLayer dl = CreateCommonDataLayer()) {
                dl.SaveJob(job);
            }
        }

        #endregion

        #region Functions

        private static CommonDataLayer CreateCommonDataLayer() {
            return (DataManager.CreateDataLayer(typeof(CommonDataLayer)) as CommonDataLayer);
        }

        #endregion

    }
}
